// ====================Window_Tip====================

class Window_Tip extends CardContainerBase {
    initialize() {
        this._text = "";
        this._showCount = 0;
        this.hide();
        this.create();
    }

    create() {
        this.createBackground();
        this.createTipSprite();
    }

    createBackground() {
        const {width, height} = this._opts;
        const bitmap = new Bitmap(width, height);
        const sprite = new Sprite(bitmap);
        const color1 = ColorManager.dimColor1();
        const color2 = ColorManager.dimColor2();
        const half = width / 2;
        bitmap.gradientFillRoundRect(0, 0, half, height, color2, color1,false, 0);
        bitmap.gradientFillRoundRect(half, 0, half, height, color1, color2,false, 0);
        this._backgroundSprite = sprite;
        this.addChild(sprite);
    }

    createTipSprite() {
        const {width, height} = this._opts;
        const bitmap = new Bitmap(width, height);
        const sprite = new Sprite(bitmap);
        bitmap.fontFace = $gameSystem.mainFontFace();
        bitmap.fontSize = height - 10;
        this._tipSprite = sprite;
        this.addChild(sprite);
    }

    pop(text) {
        this._text = text;
        this.refresh();
        this._showCount = 150;
        this.show();
    }

    refresh() {
        const {width, height} = this._opts;
        const text = this._text;
        const bitmap = this._tipSprite.bitmap;
        bitmap.clear();
        bitmap.drawText(text, 0, 0, width, height, "center");
    }

    updateContainer() {
        if (this._showCount > 0) {
            this.updateFadeIn();
            this._showCount--;
        } else {
            this.updateFadeOut();
        }
        if (this._showCount === 0 && this.alpha === 0) {
            this.hide();
        }
    }

    updateFadeIn() {
        this.alpha = (this.alpha * 255 + 16).clamp(0, 255) / 255;
    }

    updateFadeOut() {
        this.alpha = (this.alpha * 255 - 16).clamp(0, 255) / 255;
    }
}